import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/app/core/theme/app_text_theme.dart';
import 'package:my_app/app/modules/getx_tool/getx_tool_controller.dart';
import 'package:my_app/app/modules/other/other_page.dart';

/// getx_tool_page.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description: Getx工具页面
///
class GetxToolPage extends GetView<GetXToolController> {
  @override
  Widget build(BuildContext context) {
    Get.put(GetXToolController());
    return Scaffold(
        appBar: AppBar(title: Text('GetX')),
        body: ListView(
          padding: EdgeInsets.all(10.0),
          children: [
            Center(
              child: Text(
                '注:不包含国际化等相关内容,详细内容请查看官方文档',
                style: tips,
              ),
            ),
            stateManageDemo(),
            routeManageDemo(),
            toolsDemo(),
          ],
        ));
  }

  ///状态管理示例
  Widget stateManageDemo() {
    return Card(
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Column(
          children: [
            Text(
              '状态管理',
              style: cardTitle,
            ),
            Obx(() => Text('计数器案例count:${controller.count}')),
            ElevatedButton(
                onPressed: controller.increment, child: Icon(Icons.add))
          ],
        ),
      ),
    );
  }

  ///路由管理示例
  Widget routeManageDemo() {
    return Card(
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Column(
          children: [
            Text(
              '路由管理',
              style: cardTitle,
            ),
            ElevatedButton(
                onPressed: () => Get.to(OtherPage()),
                child: Text('跳转至OtherPage'))
          ],
        ),
      ),
    );
  }

  Widget toolsDemo() {
    return Card(
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Column(
          children: [
            Text(
              '实用工具',
              style: cardTitle,
            ),
            ElevatedButton(
                onPressed: () => Get.changeTheme(Get.isDarkMode
                    ? ThemeData.light(useMaterial3: true)
                    : ThemeData.dark(useMaterial3: true)),
                child: Text('切换主题')),
            Text('屏幕宽高:${Get.width},${Get.height}'),
            Text('isAndroid:${GetPlatform.isAndroid}'),
            Text('isIOS:${GetPlatform.isIOS}'),
            Text('isMacOS:${GetPlatform.isMacOS}'),
            Text('isWindows:${GetPlatform.isWindows}'),
            Text('isLinux:${GetPlatform.isLinux}'),
            Text('isFuchsia:${GetPlatform.isFuchsia}'),
          ],
        ),
      ),
    );
  }
}
